<?php
class ContenidosController extends AppController {

	var $name = 'Contenidos';

	function index() {
		$this->Contenido->recursive = 0;
		$this->set('contenidos', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid contenido', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('contenido', $this->Contenido->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Contenido->create();
			if ($this->Contenido->save($this->data)) {
				$this->Session->setFlash(__('The contenido has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The contenido could not be saved. Please, try again.', true));
			}
		}
		$admins = $this->Contenido->Admin->find('list');
		$secciones = $this->Contenido->Seccione->find('list');
		$categorias = $this->Contenido->Categoria->find('list');
		$fotos = $this->Contenido->Foto->find('list');
		$tags = $this->Contenido->Tag->find('list');
		$videos = $this->Contenido->Video->find('list');
		$this->set(compact('admins', 'secciones', 'categorias', 'fotos', 'tags', 'videos'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid contenido', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Contenido->save($this->data)) {
				$this->Session->setFlash(__('The contenido has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The contenido could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Contenido->read(null, $id);
		}
		$admins = $this->Contenido->Admin->find('list');
		$secciones = $this->Contenido->Seccione->find('list');
		$categorias = $this->Contenido->Categoria->find('list');
		$fotos = $this->Contenido->Foto->find('list');
		$tags = $this->Contenido->Tag->find('list');
		$videos = $this->Contenido->Video->find('list');
		$this->set(compact('admins', 'secciones', 'categorias', 'fotos', 'tags', 'videos'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for contenido', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Contenido->delete($id)) {
			$this->Session->setFlash(__('Contenido deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Contenido was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	function admin_index() {
		$this->layout = 'admin_layout';
		$this->Contenido->recursive = 0;
		$this->set('contenidos', $this->paginate());
	}

	function admin_view($id = null) {
		$this->layout = 'admin_layout';
		if (!$id) {
			$this->Session->setFlash(__('Invalid contenido', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('contenido', $this->Contenido->read(null, $id));
	}

	function admin_add() {
		$this->layout = 'admin_layout';
		if (!empty($this->data)) {
			$this->Contenido->create();
			if ($this->Contenido->save($this->data)) {
				$this->Session->setFlash(__('The contenido has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The contenido could not be saved. Please, try again.', true));
			}
		}
		$admins = $this->Contenido->Admin->find('list');
		$secciones = $this->Contenido->Seccione->find('list');
		$categorias = $this->Contenido->Categoria->find('list');
		$fotos = $this->Contenido->Foto->find('list');
		$tags = $this->Contenido->Tag->find('list');
		$videos = $this->Contenido->Video->find('list');
		$this->set(compact('admins', 'secciones', 'categorias', 'fotos', 'tags', 'videos'));
	}

	function admin_edit($id = null) {
		$this->layout = 'admin_layout';
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid contenido', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Contenido->save($this->data)) {
				$this->Session->setFlash(__('The contenido has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The contenido could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Contenido->read(null, $id);
		}
		$admins = $this->Contenido->Admin->find('list');
		$secciones = $this->Contenido->Seccione->find('list');
		$categorias = $this->Contenido->Categoria->find('list');
		$fotos = $this->Contenido->Foto->find('list');
		$tags = $this->Contenido->Tag->find('list');
		$videos = $this->Contenido->Video->find('list');
		$this->set(compact('admins', 'secciones', 'categorias', 'fotos', 'tags', 'videos'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for contenido', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Contenido->delete($id)) {
			$this->Session->setFlash(__('Contenido deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Contenido was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
